home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Utilities / MView / d3dxapp.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-09-27  |  5.6 KB  |  170 lines

  1. //
  2. // D3DX Application Framework
  3. // Copyright (c) 1999 Microsoft Corporation. All rights reserved.
  4. //
  5.  
  6. #ifndef __D3DXAPP_H__
  7. #define __D3DXAPP_H__
  8.  
  9. #include <d3dx9.h>
  10. struct D3DX_APPLICATION_DATA;
  11.  
  12.  
  13. // ---------------------------------------------------------------------------
  14. //
  15. // CD3DXApplication
  16. //
  17. // This class can be used to quickly create single-context fullscreen or
  18. // windowed D3DX applications.  The framework manages the window and context
  19. // objects for the application.
  20. //
  21. // ---------------------------------------------------------------------------
  22.  
  23. class CD3DXApplication
  24. {
  25. public:
  26.     CD3DXApplication();
  27.     virtual ~CD3DXApplication();
  28.  
  29.  
  30.     // Initialize
  31.     //     NOTE: If szWindowName is NULL, "D3DX Application" is used.
  32.     //           If szClassName is NULL, a default window class is created.
  33.  
  34.     HRESULT Initialize(HINSTANCE hInstance, LPCSTR szWindowName, 
  35.         LPCSTR szClassName, UINT uWidth, UINT uHeight);
  36.  
  37.  
  38.     // Reset
  39.     //     Selects a suitable device given a set of presentation parameters.
  40.     //     AreCapsSufficient is called for each device under consideration, 
  41.     //     and must pass for that device to be selected.  Reset cannot 
  42.     //     be called from within OnDraw.
  43.  
  44.     HRESULT Reset(D3DPRESENT_PARAMETERS *pPresentParameters);
  45.  
  46.  
  47.     // Run
  48.     //     Run the message loop.  While running, OnMessage is called for any 
  49.     //     windows messages received.  In addition, when the app is active, 
  50.     //     Update and Draw are called each frame.  When the app is inactive, 
  51.     //     OnIdle is called.  Run uses the application's first accelerator table 
  52.     //     resource to translate messages.
  53.     //
  54.     // Stop
  55.     //     Causes Run to terminate, once done with current frame.  If Stop is
  56.     //     called during OnUpdate, OnDraw will not be called.
  57.  
  58.     HRESULT Run();
  59.     HRESULT Stop();
  60.  
  61.  
  62.     // IsRunning
  63.     //     Is the application running?
  64.     //
  65.     // IsFullscreen
  66.     //     Are we in fullscreen mode?
  67.  
  68.     BOOL IsRunning();
  69.     BOOL IsFullscreen();
  70.  
  71.  
  72.     // WndProc
  73.     //     This is the window proc which gets used by default.  If you use a custom 
  74.     //     window class, please make sure that this window proc gets called.
  75.  
  76.     static LRESULT CALLBACK 
  77.         WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  78.  
  79.  
  80. protected:
  81.     // An application generally should not keep its own copies of these
  82.     // objects since the device may be deleted and recreated at any time.
  83.     // (When this happens, the app will be notified using OnDestoryDevice
  84.     // and OnCreateDevice.)
  85.  
  86.     HINSTANCE             m_hInstance;
  87.     HWND                  m_hwnd;
  88.     LPDIRECT3D9           m_pD3D;
  89.     LPDIRECT3DDEVICE9     m_pDevice;
  90.     D3DCAPS9              m_Caps;
  91.     D3DPRESENT_PARAMETERS m_PresentParameters;
  92.  
  93.  
  94.     // Update
  95.     //     Calls OnUpdate and updates timer.  Update can only be called
  96.     //     while application is running.
  97.     //
  98.     // Draw
  99.     //     Calls BeginScene, OnDraw, EndScene, and then Presents the
  100.     //     rendered image to the front buffer.  If the video mode has 
  101.     //     changed on a windowed app, Draw attemtps to recreate the context.
  102.     //     Draw can only be called while the application is running.
  103.  
  104.     HRESULT Update();
  105.     HRESULT Draw();
  106.  
  107.  
  108.     // AreCapsSufficient
  109.     //     Examine device capabilities to determine if a given device is
  110.     //     sufficient for the needs of this application.
  111.  
  112.     virtual BOOL AreCapsSufficient(D3DCAPS9 *pCaps, DWORD dwBehaviorFlags);
  113.  
  114.  
  115.     // OnMessage
  116.     //     Handle Windows messages.  The default implementation handles ESC
  117.     //     keypresses.
  118.     //
  119.     // OnUpdate
  120.     //     Update the scene.  All simulation should be performed here.  
  121.     //
  122.     // OnDraw
  123.     //     Draw the scene.  By the time OnDraw is called, BeginScene has already
  124.     //     been called.  OnDraw does not need to worry about calling BeginScene,
  125.     //     EndScene, or Present.  Reset may not be called from within 
  126.     //     OnDraw.  The default implementation clears the back buffer to black.
  127.     //
  128.     // OnIdle
  129.     //     Perform idle processing.  When possible, idle processing should be 
  130.     //     done in small chunks, so as not to interfere with incoming messages.
  131.     //     When no more idle processing is required, OnIdle should simply call
  132.     //     WaitMessage.  The default implementation just calls WaitMessage.
  133.  
  134.     virtual LRESULT OnMessage(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  135.     virtual HRESULT OnUpdate(float fSecsPerFrame);
  136.     virtual HRESULT OnDraw(float fAspectRatio);
  137.     virtual HRESULT OnIdle();
  138.  
  139.  
  140.     // OnCreateDevice
  141.     //     Called after device creation.  This is a good place to create
  142.     //     managed surfaces.
  143.     //
  144.     // OnResetDevice
  145.     //     Called after reset.  This is a good place to setup device state, and
  146.     //     create volatile resources, like vidmem textures.  OnResetDevice
  147.     //     is always called after OnCreateDevice.
  148.     //
  149.     // OnLostDevice
  150.     //     Called after device is lost.  This is a good place to release 
  151.     //     volatile resources, like vidmem textures.  OnLostDevice is always
  152.     //     called before OnDestroyDevice.
  153.     //
  154.     // OnDestroyDevice
  155.     //     Called before device is released.  This is a good place to release
  156.     //     managed surfaces.
  157.  
  158.     virtual HRESULT OnCreateDevice();
  159.     virtual HRESULT OnResetDevice();
  160.     virtual HRESULT OnLostDevice();
  161.     virtual HRESULT OnDestroyDevice();
  162.  
  163.  
  164. private:
  165.     D3DX_APPLICATION_DATA *m_pData;
  166. };
  167.  
  168.  
  169. #endif // __D3DXAPP_H__
  170.